// @ts-ignore
const documentfiles = require.context('./document', false, /\.html$/)
// @ts-ignore
const examplefiles = require.context('./example', false, /\.js$/)
// @ts-ignore
const backgroundfiles = require.context('./background', false, /\.js$/)

function fileToMenu(files: any) {
  let menus: Array<string> = []
  files.keys().forEach((item: string) => {
    let sp = item.split('.')
    menus.push(item.substring(2, item.length - sp[sp.length - 1].length - 1))
  })
  return menus.sort((a, b) => parseInt(a) - parseInt(b))
}

export default {
  documentMenus: fileToMenu(documentfiles),
  exampleMenus: fileToMenu(examplefiles),
  backgroundMenus: fileToMenu(backgroundfiles)
}
